package demo17_SinglePattern;

/**
 * @author kunkun
 * @className Test02_Lazy_common
 * @Description 单例模式---懒汉式---普通方法
 * @date 2025/3/8 13:12
 */
public class Test02_Lazy_common {

    private volatile static Test02_Lazy_common hungry ;//避免指令重排，加上Volatile

    public Test02_Lazy_common(){
    }

    public static Test02_Lazy_common getInstance(){
        if (hungry==null){
            hungry = new Test02_Lazy_common();
        }
        return hungry;
    }

    public static void main(String[] args) {
        Test02_Lazy_common instance1 = new Test02_Lazy_common().getInstance();
        Test02_Lazy_common instance2 = new Test02_Lazy_common().getInstance();
        System.out.println(instance1==instance2);   //true

    }
}
